package com.gao.modules.rabbitmq;

import com.gao.utils.CodeUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author anshenghui
 * @date 2021/10/31 20:45
 * @desc 测试类controller
 */
@RestController
@RequestMapping(value = "/demo")
public class RabbitMqController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping(value = "/sendVerifyCodeToRabbitMq")
    public String sendVerifyCodeToRabbitMq() {
        //生成六位随机字符
        String verifyCode = CodeUtils.getRandomVerifyCode(6);
        redisTemplate.opsForValue().setIfAbsent("SomeonesVerifyCode",verifyCode,5, TimeUnit.MINUTES);
        Map<String, Object> map = new HashMap<>();
        map.put("verifyCode",verifyCode);
        //以后自动获取当前用户的用户名
        map.put("userName","张三");
        map.put("Address","gaojiaming@qq.com");
        rabbitTemplate.convertAndSend("VerifyCodeDirectExchange", "VerifyCodeDirectRouting", map);
        return "验证码已发送";
    }
}
